package com.gdth.bank.adapter;

import java.util.List;

import com.gdth.bank.R;
import com.gdth.model.ImageItem;
import com.gdth.utils.FileUtil;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GncdListAdapter extends BaseAdapter{
	private LayoutInflater mInflater;
	
	private Context context;
	
	private List<ImageItem> mData;
	
	public GncdListAdapter(Context context, List<ImageItem> mData) {
	    this.mInflater = LayoutInflater.from(context);
	    this.context = context;
	    this.mData = mData;
    }
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageItem model = mData.get(position);
		
		ViewHolder holder;
        //观察convertView随ListView滚动情况            
        if (convertView == null) {
        	convertView = mInflater.inflate(R.layout.item_menu_listview, null);
        	holder = new ViewHolder();
        	/*得到各个控件的对象*/                    
        	holder.img_tp = (ImageView) convertView.findViewById(R.id.gncd_item_tp);
        	holder.txt_val = (TextView) convertView.findViewById(R.id.gncd_item_val);
        	holder.img_detail = (ImageView) convertView.findViewById(R.id.gncd_item_detail);
        	convertView.setTag(holder);//绑定ViewHolder对象                   
    	}else{
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象                  
        }

        holder.txt_val.setText(model.getValue());
        if (model.getImg() != null){
			Bitmap bitmap = FileUtil.getImageFromAssetsFile(context, model.getImg());
			holder.img_tp.setImageBitmap(bitmap);
	    }
        return convertView;
	}
	
	public final class ViewHolder{
		public ImageView img_tp;
		public TextView txt_val;
		public ImageView img_detail;
    }
}
